/*
 * BasicCache.h
 *
 *  Created on: Oct 22, 2011
 *      Author: gassa
 */

#ifndef BASICCACHE_H_
#define BASICCACHE_H_

#include <map>
#include <string>
#include <iostream>
#include "../include/config.h"

using namespace std;

struct PostingItem {
	//term-frequency
	int tf;
	PostingItem(const int _tf) : tf(_tf) {}
};
//key:docId
typedef map<size_t, PostingItem*> PostingListContainer;

class Term{
public:
	string termString;
	size_t tid;
	size_t offset;
	int df;
	PostingListContainer* pl;
	string plString;
	Term(size_t _tid, size_t _offset){
		tid = _tid;
		offset = _offset;
	}
};

class IndexLoader {
	static bool instanceFlag;
	static IndexLoader* instance;
	config *configInstance;
	int barrelNumber;
	map<char, int> barrelMapper;
	vector<map<size_t, size_t>*> indexMaster;
	IndexLoader();
public:
	map< string, Term> termMapper;
	map<size_t, size_t*> fileMapper;
	static IndexLoader* getInstance();
	void setBarrelNumberToMap();
	virtual ~IndexLoader();
	void loadTermDict();
	void loadMasterIndex();
	void loadFileDict();
	string getFileNameFromId(size_t barOff[2]);
	Term* loadPostingList(string termString);
	string readPostinglistByOffset(int barrelNumber, int offset);
	void postingListStringToObject(Term& t);
};
#endif /* BASICCACHE_H_ */
